package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.ProductUnit;
import com.spzx.product.service.IProductUnitService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 商品单位 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/productUnit")
public class ProductUnitController extends BaseController {

@Autowired
    IProductUnitService productUnitService;
    @Operation(summary = "产品单位分页查询")
@GetMapping("/list")
    public TableDataInfo list(@RequestParam(value = "name",required = false) String name){
    startPage();
    List<ProductUnit> list=productUnitService.selectProductUnitList(name);
    return getDataTable(list);
}
@Operation(summary = "获取商品单位详细信息")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id")Long id){
    return AjaxResult.success(productUnitService.getById(id));
}
@Operation(summary = "新增商品单位")
@PostMapping
    public AjaxResult add(@RequestBody ProductUnit productUnit){
    productUnitService.save(productUnit);
      return  AjaxResult.success();
}
@Operation(summary = "删除产品单位")
@DeleteMapping
    public AjaxResult remove(@PathVariable("ids") List<Long> ids){
        productUnitService.removeByIds(ids);
                return AjaxResult.success();
}
@PutMapping
    public AjaxResult update(@RequestBody ProductUnit productUnit){
        productUnitService.update(productUnit,null);
        return AjaxResult.success();
}

@Operation(summary = "查询所有商品单位")
    @GetMapping("/getUnitAll")
    public AjaxResult getUnitAll(){
        List<ProductUnit> list =productUnitService.list();
        return AjaxResult.success(list);
}

}
